//
//  LXDSingerViewController.m
//  BLDMusics
//
//  Created by lxd on 16/3/20.
//  Copyright © 2016年 李晓丹. All rights reserved.
//

#import "LXDSingerViewController.h"

@interface LXDSingerViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionView *collection;
/**
 *  元数据
 */
@property (nonatomic, retain) NSMutableArray *modelArr;

@property (nonatomic, strong) UIVisualEffectView *visualEfView; /**< 毛玻璃 */

@end

@implementation LXDSingerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"歌手";
    
    [self createCollection];
    [self dataHandle];
}


#pragma mark - 创建collection
- (void)createCollection {
    self.modelArr = [NSMutableArray array];
    
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"ground.jpg"]];
    // 毛玻璃
    self.visualEfView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
    _visualEfView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    _visualEfView.alpha = 0.8;
    _visualEfView.userInteractionEnabled = YES;
    [self.view addSubview:_visualEfView];
    
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    layout.minimumInteritemSpacing = 9;
    layout.minimumLineSpacing = 10;
    layout.sectionInset = UIEdgeInsetsMake(10, 10, 10, 10);
    layout.itemSize = CGSizeMake((SCREEN_WIDTH - 40) / 3, (SCREEN_WIDTH - 40) / 3 + 20);
    
    self.collection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH - 60 - 64) collectionViewLayout:layout];
    _collection.delegate = self;
    _collection.dataSource = self;
    _collection.backgroundColor = [UIColor clearColor];
    [self.view addSubview:_collection];
    [_collection registerClass:[LXDSingerCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    
}


#pragma mark - 协议方法
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return _modelArr.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    LXDSingerCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    LXDSingerModel *model = _modelArr[indexPath.row];
    cell.model = model;
    return cell;
}
// 点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    LXDSelectSingerViewController *vc = [[LXDSelectSingerViewController alloc] init];
    LXDSingerModel *model = _modelArr[indexPath.row];
    vc.ID = model.ID;
    [self.navigationController pushViewController:vc animated:YES];
}





#pragma mark - 数据解析
- (void)dataHandle {
    [APPTools GETWithURL:@"http://v1.ard.tj.itlily.com/ttpod?a=getnewttpod&id=46" par:nil success:^(id responseObject) {
        self.modelArr = [LXDSingerModel modelHandleWithArray:responseObject[@"data"]];
        [_collection reloadData];
    } filed:^(NSError *error) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
